package org.bwgl.demo6.controller;

import org.bwgl.demo6.mapper.UserMapper;
import org.bwgl.demo6.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserMapper userMapper;
    @GetMapping("/user")
    public String getAlluser(){
//        List<User> users = userMapper.getAllUser();
        List users = userMapper.selectList(null);
        System.out.println("users = " + users);
        return "获得所有用户信息";
    }

    @PostMapping("/user")
    public String insertUser(User user){
//        userMapper.addUser(user);
        userMapper.insert(user);
        return "增加一个用户";
    }

    @PutMapping("/user")
    public String updateUser(User user){
//        userMapper.updateUser(user);
        userMapper.updateById(user);
        return "更新一个用户";
    }

    @DeleteMapping("/user")
    public String deleteUser(){
        return "删除所有用户";
    }

    @GetMapping("/user/{id}")
    public String getUser(@PathVariable int id){
//        User user = userMapper.getUser(id);
        User user = userMapper.selectById(id);
        System.out.println("users = " + user);
        return "获得一个用户信息";
    }

    @DeleteMapping("/user/{id}")
    public String deleteUser(@PathVariable int id){
        return "删除一个用户";
    }
}
